package com.dmooo.yxmmerchant.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import java.util.Date;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.common.util.DateUtil;
import com.dmooo.yxmmerchant.R;
import com.dmooo.yxmmerchant.domain.CouponListBean;

import java.util.List;

public class CouponListAdapter extends BaseQuickAdapter<CouponListBean.Item,BaseViewHolder> {
    public CouponListAdapter(int layoutResId, @Nullable List<CouponListBean.Item> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, CouponListBean.Item item) {
        helper.setText(R.id.txt_money,item.money);
        helper.setText(R.id.txt_use_condition,"满"+item.condition_money+"可用");
        switch (item.type){
            case "5":
                helper.setText(R.id.txt_is_own,"[店铺通用]");
                break;
            case "4":
                helper.setText(R.id.txt_is_own,"[商品专用]");
                break;
            case "6":
                helper.setText(R.id.txt_is_own,"[服务专用]");
                break;
        }
        helper.setText(R.id.txt_time,"已领取"+item.send_num+",共"+item.all_num+"张");
        if(DateUtil.getDate(item.send_end_time).getTime()<new Date().getTime()){
            helper.getView(R.id.txt_del_coupon).setVisibility(View.GONE);
            helper.getView(R.id.txt_edit_coupon).setVisibility(View.GONE);
            helper.getView(R.id.img_used).setVisibility(View.GONE);
            helper.getView(R.id.img_over_date).setVisibility(View.VISIBLE);
        }else{
            helper.getView(R.id.txt_del_coupon).setVisibility(View.VISIBLE);
            helper.getView(R.id.txt_edit_coupon).setVisibility(View.VISIBLE);
            helper.getView(R.id.img_used).setVisibility(View.GONE);
            helper.getView(R.id.img_over_date).setVisibility(View.GONE);
        }
        helper.addOnClickListener(R.id.txt_del_coupon).addOnClickListener(R.id.txt_edit_coupon);
    }
}
